//
//  HMHomeRandDataCell.m
//  HowToDo
//
//  Created by 胡坤 on 2017/1/4.
//  Copyright © 2017年 KY. All rights reserved.
//

#import "HMHomeRandDataCell.h"
#import "HMHomeCommanLayOut.h"
#import "HMRankDataCollectionCell.h"

@interface HMHomeRandDataCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,strong)UICollectionView *rankMainCollection;
@end

static NSString* rankDataCollectionCellID = @"homerankDataCollectionCellID ";
@implementation HMHomeRandDataCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setUPUI];
    }
    return self;
}
- (void)setUPUI
{
    [self.contentView addSubview:self.rankMainCollection];
    self.rankMainCollection.backgroundColor = [UIColor whiteColor];
    self.rankMainCollection.dataSource = self;
    self.rankMainCollection.delegate = self;
    [self.rankMainCollection registerNib:[UINib nibWithNibName:@"HMRankDataCollectionCell" bundle:nil] forCellWithReuseIdentifier:rankDataCollectionCellID];
    [self.rankMainCollection mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.top.left.right.offset(0);
        make.height.offset(150);
        make.bottom.equalTo(self.contentView);
    }];
}
#pragma mark -- dataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.rankDataList.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HMRankDataCollectionCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:rankDataCollectionCellID forIndexPath:indexPath];
    cell.rankData = self.rankDataList[indexPath.item];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.selectedItemCallBack(indexPath);
}
//获取最新数据，刷新界面
- (void)setRankDataList:(NSArray<HTDRankData *> *)rankDataList
{
    _rankDataList = rankDataList;
    [self.rankMainCollection reloadData];
}
- (UICollectionView *)rankMainCollection
{
    if (!_rankMainCollection)
    {
        HMHomeCommanLayOut* layOut = [[HMHomeCommanLayOut alloc]init];
        _rankMainCollection = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layOut];
    }
    return _rankMainCollection;
}

@end
